#include "XSystem/XCore.h"
#include "testwindow.h"

using namespace std;

int main()
{	
	// Default window
	sf::RenderWindow app(sf::VideoMode(800, 600, 32), "-");

	// Load the resources manager
	XResourcesManager data(&app);
	data.DisplayLogs(true);

	// Create the window
	app.Create(sf::VideoMode(data.GetInt("s_resolutionX"), data.GetInt("s_resolutionY"), 32), "XGui - Sample");
	app.SetFramerateLimit(60);

	// Debug: build version
	data.SetString("d_version", "0.0.2");
	data.NewLog("Program version '"+data.GetString("d_version")+"'");

	// Debug: date and time
	time_t t = time(0);
    struct tm * now = localtime(&t);
	ostringstream ssdate;
    ssdate << (now->tm_mon + 1) << '-' << now->tm_mday << '-' << (now->tm_year + 1900) << " at " << now->tm_hour << ":" << now->tm_min << endl;
	data.NewLog("Excecuted "+ssdate.str());

	// Create the test window (ui)
	XUserInterface ui;
	ui.AddWindow(new TestWindow(&data));
	ui.AddWindow(new TestWindow(&data));
	ui.AddWindow(new TestWindow(&data));

	// Main loop
	const sf::Input& input = app.GetInput();
	while(app.IsOpened())
	{
		// Check events
		sf::Event Event;
		while(app.GetEvent(Event))
		{
			if(Event.Type == sf::Event::Closed)
				app.Close();

			ui.CheckEvent(Event);
		}

		// Check input
		ui.CheckState(input);

		// Clear
		app.Clear();

		// Draws
		ui.Draw();

		// Display
		app.Display();
	}

	data.Close();

	return 0;
}
